﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>复选框全选（二）</title>
    <script language="javascript">
        function checkAll(str){
            let a = document.getElementsByName(str);
            let n = a.length;   
            for(let i = 0;i< n;i++){
                a[i].checked = window.event.srcElement.checked;
            }
        }
        
    </script>
</head>
<body>
<input type=checkbox name=All onclick="checkAll('ck')">全选<br/>
<input type=checkbox name=ck  >体育<br/>
<input type=checkbox name=ck  >旅游<br/>
<input type=checkbox name=ck  >饮食<br/>
<input type=checkbox name=ck  >影视<br/>
<input type=checkbox name=ck  >音乐<br/><br/>
</body>
</html>